/*
** loop.c for  in /home/faye_m//zappy-2011/new_server/src
** 
** Made by mouhamed faye
** Login   <faye_m@epitech.net>
** 
** Started on  Fri Jul  8 22:22:21 2011 mouhamed faye
** Last update Sun Jul 10 11:57:31 2011 mouhamed faye
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include "types.h"

void    loop(T_env *e, t_server_params *p)
{
  config_server(e, p);
  for ( ; ; )
    {
      e->read_fds = e->master;
      if (select(e->fdmax + 1, &e->read_fds, NULL, NULL, NULL) == -1)
	printf("error select : segfault or broken pipe!!!");
      for (e->i = 0; e->i <= e->fdmax; e->i++)
	{
          if (FD_ISSET(e->i, &e->read_fds))
            {
              if (e->i == e->listener)
		  accept_client(e);
              else
                read_buff_from_socket(e, e->i, p);
            }
	}
    }
}
